<template>
  <div class="app-container">
      <!-- 查询条件区域-->
        <el-form :model="queryParams" ref="queryForm" size="small" :inline="true" v-show="showSearch" >
          <el-form-item label="工艺编码" prop="process_num">
            <el-input
              v-model="queryParams.process_num"
              placeholder="请输入工艺编码"
              clearable
              @keyup.enter.native="handleQuery"
              size="small"
            />
          </el-form-item>
          <el-form-item label="工艺名称" prop="process_name">
            <el-input
              v-model="queryParams.process_name"
              placeholder="请输入工艺名称"
              clearable
              @keyup.enter.native="handleQuery"
              size="small"
            />
          </el-form-item>
          <el-form-item>
            <el-button type="primary" icon="el-icon-search" size="small" @click="handleQuery">搜索</el-button>
            <el-button icon="el-icon-refresh" size="small" @click="resetQuery">重置</el-button>
          </el-form-item>
        </el-form>
        <!--增删改查按钮区域-->
        <el-row :gutter="10" class="mb8">
          <el-col :span="1.5">
            <el-button
              type="primary"
              plain
              icon="el-icon-plus"
              size="mini"
              @click="handleAdd"
              v-hasPermi="['robot:processbody:add']"
            >新增</el-button>
          </el-col>
          <el-col :span="1.5">
            <el-button
              type="success"
              plain
              icon="el-icon-edit"
              size="mini"
              :disabled="single"
              @click="handleUpdate"
              v-hasPermi="['robot:processbody:edit']"
            >修改</el-button>
          </el-col>
          <el-col :span="1.5">
            <el-button
              type="danger"
              plain
              icon="el-icon-delete"
              size="mini"
              :disabled="multiple"
              @click="handleDelete"
              v-hasPermi="['robot:processbody:remove']"
            >删除</el-button>
          </el-col>
         <right-toolbar :showSearch.sync="showSearch" @queryTable="getList"></right-toolbar>
        </el-row>
        <!--右边 数据列表区域-->
        <el-table v-loading="loading" :data="processbodyList" @selection-change="handleSelectionChange" :cell-style="{borderColor:'rgb(1 5 43)'}" :header-cell-style="{borderColor: 'rgb(1 5 43)'}">
          <el-table-column type="selection" width="55" align="center"/>
<!--          <el-table-column label="序号" type="index" align="center" prop="id"/>-->
          <el-table-column label="工艺编码" align="center" prop="process_num"/>
          <el-table-column label="工艺名称" align="center" prop="process_name"/>
<!--
          <el-table-column label="站点名称" align="center" prop="site_name" />
-->
          <el-table-column label="创建时间" align="center" prop="creater_time" width="200">
            <template slot-scope="scope">
              <span>{{ parseTime(scope.row.creater_time) }}</span>
            </template>
          </el-table-column>
          <el-table-column label="操作" align="center" class-name="small-padding fixed-width"  width="200">
            <template slot-scope="scope">
              <el-button
                size="mini"
                type="text"
                icon="el-icon-edit"
                @click="handleUpdate(scope.row)"
                v-hasPermi="['robot:processbody:edit']"
              >修改</el-button>
              <el-button
                size="mini"
                type="text"
                icon="el-icon-delete"
                @click="handleDelete(scope.row)"
                v-hasPermi="['robot:processbody:remove']"
              >删除</el-button>
            </template>
          </el-table-column>
        </el-table>
        <!--列表分页区域-->
        <pagination
          v-show="total>0"
          :total="total"
          :page.sync="queryParams.pageNum"
          :limit.sync="queryParams.pageSize"
          @pagination="getList" style="background:rgb(1 5 43);"
        />
    <!-- 添加或修改对话框 -->
    <el-dialog :title="title" :visible.sync="open" width="600px" append-to-body>
      <el-form ref="form" :model="form" :rules="rules" label-width="80px">
        <el-row>
<!--          <el-col :span="12">
            <el-form-item label="站点名称" prop="site_id">
              <el-select v-model="form.site_id" placeholder="请选择站点名称">
                <el-option
                  v-for="item in siteList"
                  :key="item.id"
                  :label="item.site_name"
                  :value="item.id"
                ></el-option>
              </el-select>
            </el-form-item>
          </el-col>-->
        <el-col :span="24">
          <el-form-item label="工艺名称" prop="process_name">
            <el-input v-model="form.process_name" placeholder="请输入工艺名称" />
          </el-form-item>
        </el-col>
        <el-col :span="24">
          <el-form-item label="备注">
            <el-input v-model="form.remark" type="textarea" placeholder="请输入内容(0-255)"></el-input>
          </el-form-item>
        </el-col>
        </el-row>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button type="primary" @click="submitForm">确 定</el-button>
        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>
<script>
import {
  addProcessBody,
  delProcessBody,
  getProcessBody,
  listProcessBody,
  updateProcessBody
} from "@/api/robot/processbody/processbody";
import {listSite} from "@/api/robot/site/site";
import "@/assets/styles/robt-bg.css";

export default {
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      process_names:[],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 站点表格数据
      siteList: [],
      // 工艺体表格数据
      processbodyList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      site_name: undefined,
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 8,
        process_name: undefined,
        process_num: undefined,
        creater_time: undefined,
        site_id: undefined,
        site_name: undefined
      },
      queryParamsc: {
        process_name: undefined,
        process_num: undefined,
        creater_time: undefined,
        site_id: undefined,
        site_name: undefined
      },
      // 表单参数
      form: {},
      // 表单校验
      rules: {
        process_name: [
          { required: true, message: "工艺名称不能为空", trigger: "blur" }
        ] ,
        site_id: [
          { required: true, message: "站点名称不能为空"}
        ]
      }
    };
  },
  created() {
    //初始化页面加载方法
    this.getList();//工艺列表
  },
  methods: {
    /** 查询站点列表 */
  /*  getSiteList() {
      this.loading = true;
      listSite(this.queryParams).then(response => {
        this.siteList = response.rows;
        this.loading = false;
      });
    },*/
    /** 查询工艺体列表 */
    getList() {
      this.loading = true;
      listProcessBody(this.queryParams).then(response => {
        this.processbodyList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.form = {
        id: undefined,
        process_num: undefined,
        process_name: undefined,
        creater_id:undefined,
        creater_time:undefined,
        site_id: undefined,
        site_name: undefined,
        remark: undefined
      };
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.loading = true;
      this.queryParams.site_id=null;
      this.resetForm("queryForm");
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map(item => item.id)
      this.process_names = selection.map(item => item.process_name)
      this.single = selection.length!=1
      this.multiple = !selection.length
    },
    /** 新增按钮操作 */
    handleAdd() {
      this.reset();
      this.open = true;
      this.title = "新增工艺";
      //this.getSiteList();//新增修改页面
    },
    /** 修改按钮操作 */
    handleUpdate(row) {
      this.reset();
      const id = row.id || this.ids
      getProcessBody(id).then(response => {
        this.form = response.data;
        this.open = true;
        this.title = "修改工艺";
       // this.getSiteList();//新增修改页面
      });
    },
    /** 提交按钮 */
    submitForm: function() {
      this.$refs["form"].validate(valid => {
        if (valid) {
          if (this.form.id != undefined) {
            updateProcessBody(this.form).then(response => {
              this.$modal.msgSuccess("修改成功");
              this.open = false;
              this.getList();
            });
          } else {
            addProcessBody(this.form).then(response => {
              this.$modal.msgSuccess("新增成功");
              this.open = false;
              this.getList();
            });
          }
        }
      });
    },
    /** 删除按钮操作 */
    handleDelete(row) {
      const ids = row.id || this.ids
      const process_names= row.process_name || this.process_names
      this.$modal.confirm('是否确认删除工艺名称为"' + process_names + '"的数据项？').then(function() {
      // this.$modal.confirm('是否确认删除选中的数据项？').then(function() {
        return delProcessBody(ids);
      }).then(() => {
        this.getList();
        this.$modal.msgSuccess("删除成功");
      }).catch(() => {});
    }
  }
};
</script>
